package com.nulldev.util.java.extendedUI.cSwing;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.nulldev.util.java.JVMUtil;
import com.nulldev.util.java.swing.SwingUtil;
import com.nulldev.util.java.swing.extSwing.lookandfeel.themes.Theme;
import com.nulldev.util.java.swing.font.FontManager;
import com.nulldev.util.math.MathUtil;
import com.nulldev.util.other.ArrayUtils;
import com.nulldev.util.threading.v3.RunnableWorker;
import com.nulldev.util.threading.v3.ThreadDispatcher;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JScrollPane;
import javax.swing.JList;

public class cSwingElementsDemo extends cSwing {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main() {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					cSwingElementsDemo frame = new cSwingElementsDemo();
					SwingUtil.centerFrame(frame);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public cSwingElementsDemo() {
		setTitle("cSwing: Item Demos");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblProgressBarDemo = new JLabel("Progress Bar Demo");
		
		final cProgressBar panel = new cProgressBar();
		panel.setPercent(53.6f);
		
		ThreadDispatcher.instance().addTask(RunnableWorker.fromRunnable(new Runnable() {
			
			@Override
			public void run() {
				boolean up = true;
				float value = 50;
				while (true) {
					if (value < 0 || value > 100) {
						up = !up;
					}
					if (up) {
						value += 0.5;
					}else {
						value -= 0.5;
					}
					panel.setPercent(value);
					try {
						Thread.sleep(SwingUtil.FPS_60);
					} catch (InterruptedException e) {
					}
				}
			}
		}));
		
		JScrollPane scrollPane = new JScrollPane();
		
		JLabel lblFontsSupportedBy = new JLabel("Fonts supported by fontAPI");
		
		JLabel lblLegacyThemesSupported = new JLabel("Legacy Themes Supported");
		
		JScrollPane scrollPane_1 = new JScrollPane();
		
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addComponent(scrollPane_1, GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
								.addComponent(panel, GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
								.addComponent(lblProgressBarDemo)
								.addComponent(lblFontsSupportedBy)
								.addComponent(lblLegacyThemesSupported))
							.addContainerGap())))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblProgressBarDemo)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblFontsSupportedBy)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(scrollPane_1, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblLegacyThemesSupported)
					.addContainerGap())
		);
		
		JList list_1 = new JList(Theme.values());
		scrollPane_1.setViewportView(list_1);
		
		JList list = new JList(
				ArrayUtils.arrayListToArray(FontManager.getGlobalFontsBeta()));
		scrollPane.setViewportView(list);
		contentPane.setLayout(gl_contentPane);
	}
}
